<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item prop="deptId">
        <treeselect v-model="queryParams.deptId" :options="deptOptions" :show-count="true" placeholder="请选择部门"
          style="width: 480px"/>
      </el-form-item> -->
      <el-form-item prop="storeId">
        <!-- <treeselect v-model="queryParams.storeId" :options="storeOptions" :show-count="true" placeholder="请选择仓库"
          style="width: 480px" size="mini"/> -->
          <el-select v-model="queryParams.storeId" placeholder="仓库" clearable size="small">
              <el-option v-for="dict in storeOptions" :key="dict.id" :label="dict.label"
                :value="dict.id" />
            </el-select>
      </el-form-item>
      <el-form-item prop="areaId" v-if="queryParams.storeId">
        <el-select v-model="queryParams.areaId" placeholder="请选择库区" clearable size="small">
          <el-option v-for="item in storeAreaOptions" :key="item.id" :label="item.name"
            :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item prop="cabinetGroupId" v-if="(ano == 'ZX'||ano == 'DX')?false:true && queryParams.areaId">
        <el-select v-model="queryParams.cabinetGroupId" placeholder="请选择货柜" clearable size="small">
          <el-option v-for="item in cabinetGroupOptions" :key="item.id" :label="item.name"
            :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item prop="cabinetId" v-if="(ano == 'CL'||ano == 'ZX'||ano == 'DX')?false:true && queryParams.cabinetGroupId">
        <el-select v-model="queryParams.cabinetId" placeholder="请选择货架" clearable size="small">
          <el-option v-for="item in cabinetOptions" :key="item.id" :label="item.name"
            :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item prop="floors" v-if="ano == 'PT' && queryParams.cabinetGroupId">
        <el-select v-model="queryParams.floors" placeholder="请选择层数" clearable size="small">
          <el-option v-for="item in floorsOptions" :key="item.value" :label="item.name"
            :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item prop="locatorId" v-if="(ano == 'ZX'||ano == 'DX')?false:true && queryParams.cabinetGroupId">
        <el-select v-model="queryParams.locatorIds" placeholder="请选择格口" clearable size="small" multiple>
          <el-option v-for="item in locatorOptions" :key="item.id" :label="item.name"
            :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item prop="pno">
        <el-input v-model="queryParams.pno" placeholder="物品编号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item prop="name">
        <el-input v-model="queryParams.name" placeholder="物品名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-date-picker v-model="daterangeIntime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="入库起始日期" end-placeholder="入库截止日期"></el-date-picker>
      </el-form-item>

      <!-- <el-form-item label="最新盘点时间">
        <el-date-picker v-model="daterangeLastTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item> -->

      <!-- <el-form-item label="下一次盘点时间">
        <el-date-picker v-model="daterangeNextTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item> -->


      <el-form-item prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option v-for="dict in dict.type.wms_stock_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="更新时间">
        <el-date-picker v-model="daterangeUpdateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>

      <el-form-item label="更新人" prop="updateBy">
        <el-input v-model="queryParams.updateBy" placeholder="请输入更新人" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="创建人" prop="createBy">
        <el-input v-model="queryParams.createBy" placeholder="请输入创建人" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->

      <!-- <el-form-item label="删除标识" prop="delFlag">
        <el-select v-model="queryParams.delFlag" placeholder="请选择删除标识" clearable size="small">
          <el-option v-for="dict in dict.type.sys_del_flag" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row class="mb10">
      <el-col :span="3">
        <el-radio-group v-model="xzTabVal" @change="xzTabChange"  size="mini" style="margin-right: 30px">
          <el-radio-button v-for="tab in xzTabs" :label="tab.label">
            <el-badge :value="tab.badge" class="item">
              {{ tab.name }}
            </el-badge>
          </el-radio-button>
        </el-radio-group>
      </el-col>
      <el-col :span="21">
        <template v-for="item in statisticsOptions">
          <el-badge :value="item.totals" class="item ml10" :is-dot="item.totals>0?false:true" :type="item.totals>0?'danger':'info'">
            <el-button @click="statisticsChange(item)" size="mini" :type="item.region == queryParams.region ? 'primary':''" :plain="item.region == queryParams.region">{{item.regionName}}</el-button>
          </el-badge>
        </template>
      </el-col>
    </el-row>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['wms:inventory:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['wms:inventory:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['wms:inventory:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['wms:inventory:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="inventoryList" show-summary  :summary-method="getSummaries"   @selection-change="handleSelectionChange" border stripe>
      <el-table-column type="index" width="55" align="center" fixed="left" />
      <!-- <el-table-column label="库存ID" align="center" prop="id" v-if="true" /> -->
      <el-table-column label="编号" prop="pno" width="250" fixed="left" >
            <template slot-scope="scope">
              <el-link type="primary" @click="handleInfo(scope.row)">{{scope.row.pno}}</el-link>
            </template>
          </el-table-column>
      <!-- <el-table-column label="RFID" align="center" prop="rfid" /> -->
      <el-table-column label="物品名称" prop="name" width="160" fixed="left"/>
      <el-table-column label="扣押单位" prop="deptName"  width="280"/>
      <el-table-column label="所属权单位" prop="belongDeptName"  width="100">
      <template slot-scope="scope">
         <el-tag v-if="!scope.row.belongDeptName || scope.row.belongDeptName == '' || scope.row.belongDeptName.substr(0,1) == '3'
         || (
         scope.row.belongDeptName.substr(0,1) != '8' && scope.row.belongDeptName!='检察院'
         && scope.row.belongDeptName.substr(0,1) != '1' && scope.row.belongDeptName!=' '
         )">公安</el-tag>
         <el-tag type="success" v-else-if="scope.row.belongDeptName.substr(0,1) == '8' || scope.row.belongDeptName=='检察院'">检察院</el-tag>
         <el-tag type="warning" v-else-if="scope.row.belongDeptName.substr(0,1) == '1' || scope.row.belongDeptName=='法院'">法院</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="仓库" prop="storeName" width="80"/>
      <el-table-column label="库区" prop="areaName"  width="120"/>
      <el-table-column label="存放位置" prop="locatorName" width="260">
        <template slot-scope="scope">
          {{scope.row.groupName?scope.row.groupName+'/':''}}
          {{scope.row.cabinetName?scope.row.cabinetName+'/':''}}
          {{scope.row.locatorName?scope.row.locatorName:''}}
        </template>
      </el-table-column>
      <el-table-column label="物品编码" prop="qrcode"  width="260"/>
      <el-table-column label="上一次盘点时间" align="center" prop="lastTime"  width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="部门" prop="officeName"  width="280"/> -->
      <!-- <el-table-column label="下次盘点时间" align="center" prop="nextTime"  width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="入库时间" align="center" prop="intime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.intime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入库数" align="center" prop="innums" width="80" fixed="right">
        <template slot-scope="scope">
          <el-tag type="primary" plain size="small" v-if="scope.row.innums > 0">{{scope.row.innums}}</el-tag>
          <el-badge type="info" class="item" is-dot v-else></el-badge>
        </template>
      </el-table-column>
      <el-table-column label="出库数" align="center" prop="outnums" width="80" fixed="right">
        <template slot-scope="scope">
          <!-- <el-badge :value="scope.row.outnums?scope.row.outnums:0" type="info" class="item"></el-badge> -->
          <el-tag type="warning" plain size="small" v-if="scope.row.outnums > 0">{{scope.row.outnums}}</el-tag>
          <el-badge type="info" class="item" is-dot v-else></el-badge>
        </template>
      </el-table-column>
      <el-table-column label="处置数" align="center" prop="deals" width="80" fixed="right">
        <template slot-scope="scope">
          <!-- <el-badge :value="scope.row.deals?scope.row.deals:0" :type="scope.row.deals > 0 ?'danger':'info'" class="item"></el-badge> -->
          <el-tag type="danger" plain size="small" v-if="scope.row.deals > 0">{{scope.row.deals}}</el-tag>
          <el-badge type="info" class="item" is-dot v-else></el-badge>
        </template>
      </el-table-column>
      <el-table-column label="调用数" align="center" prop="tnums" width="80" fixed="right">
        <template slot-scope="scope">
          <!-- <el-badge :value="scope.row.tnums?scope.row.tnums:0" :type="scope.row.tnums > 0 ?'warning':'info'" class="item"></el-badge> -->
          <el-tag type="warning" plain size="small" v-if="scope.row.tnums > 0">{{scope.row.tnums}}</el-tag>
          <el-badge type="info" class="item" is-dot v-else></el-badge>
        </template>
      </el-table-column>
      <el-table-column label="归还数" align="center" prop="rnums" width="80" fixed="right">
        <template slot-scope="scope">
          <!-- <el-badge :value="scope.row.rnums?scope.row.rnums:0" :type="scope.row.rnums > 0 ?'success':'info'" class="item"></el-badge> -->
          <el-tag type="success" plain size="small" v-if="scope.row.rnums > 0">{{scope.row.rnums}}</el-tag>
          <el-badge type="info" class="item" is-dot v-else></el-badge>
        </template>
      </el-table-column>
      <el-table-column label="库存数" align="center" prop="nums" width="80" fixed="right">
        <template slot-scope="scope">
          <!-- <el-badge :value="scope.row.nums?scope.row.nums:0" :type="scope.row.nums > 0 ?'primary':'info'" class="item" :is-dot="scope.row.nums > 0?false:true"></el-badge> -->
          <!-- <el-button :type="scope.row.nums > 0 ?'primary':'info'" circle plain size="mini">{{scope.row.nums}}</el-button> -->
          <el-tag type="primary" plain size="small" v-if="scope.row.nums > 0">{{scope.row.nums}}</el-tag>
          <el-badge type="info" class="item" is-dot v-else></el-badge>
        </template>
      </el-table-column>
      <!-- <el-table-column label="附件" align="center" prop="pics" width="180"/> -->
     <!-- <el-table-column label="状态" align="center" prop="status" width="80" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_stock_status" :value="scope.row.status" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
     <!-- <el-table-column label="创建人" align="center" prop="createBy" width="80"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy" width="80"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{m}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="删除标识" align="center" prop="delFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_del_flag" :value="scope.row.delFlag" />
        </template>
      </el-table-column> -->
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改库存对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="880px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">

        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="物品编号" prop="pno">
              <el-input v-model="form.pno" placeholder="请输入物品编号" />
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="RFID" prop="rfid">
              <el-input v-model="form.rfid" placeholder="请输入RFID" />
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="物品名称" prop="name">
              <el-input v-model="form.name" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="入库时间" prop="intime">
              <el-date-picker clearable size="small" v-model="form.intime" type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择入库时间">
              </el-date-picker>
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="入库数量" prop="innums">
              <el-input v-model="form.innums" placeholder="请输入入库数量" />
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="库存数量" prop="nums">
              <el-input v-model="form.nums" placeholder="请输入库存数量" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="处置数量" prop="deals">
              <el-input v-model="form.deals" placeholder="请输入处置数量" />
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="最新盘点时间" prop="lastTime">
              <el-date-picker clearable size="small" v-model="form.lastTime" type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择最新盘点时间">
              </el-date-picker>
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="下一次盘点时间" prop="nextTime">
              <el-date-picker clearable size="small" v-model="form.nextTime" type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择下一次盘点时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="机构id" prop="deptId">
              <el-input v-model="form.deptId" placeholder="请输入机构id" />
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择状态">
                <el-option v-for="dict in dict.type.wms_stock_status" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="图片附件" prop="pics">
              <el-input v-model="form.pics" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer :title="title" :visible.sync="drawer" :before-close="handleClose" size="70vw">
        <el-card>
          <el-tabs v-model="activeName">
            <el-tab-pane label="财物信息" name="0">
             <el-descriptions border :column="3" direction="vertical">
                 <el-descriptions-item label="编号">{{propertyForm.pno}}</el-descriptions-item>
                 <el-descriptions-item label="名称">{{propertyForm.name}}</el-descriptions-item>
                 <el-descriptions-item label="RFID">{{propertyForm.rfid}}</el-descriptions-item>
                 <el-descriptions-item label="分类">{{(propertyForm.classifyName?propertyForm.classifyName:'')+(propertyForm.secondClassifyName?'/'+propertyForm.secondClassifyName:'')+(propertyForm.thirdClassifyName?'/'+propertyForm.thirdClassifyName:'')}}</el-descriptions-item>
                 <el-descriptions-item label="所属单位">{{propertyForm.deptName}}</el-descriptions-item>
                 <el-descriptions-item label="保管单位">{{propertyForm.transferName}}</el-descriptions-item>
                 <el-descriptions-item label="扣押单位">{{propertyForm.officeName}}</el-descriptions-item>
                 <el-descriptions-item label="办案民警">{{propertyForm.personName}}</el-descriptions-item>
                 <el-descriptions-item label="保管场所">{{propertyForm.store}}</el-descriptions-item>
                 <el-descriptions-item  v-if="propertyForm.istoreId == 'f2060d9fd9814f0e88a8a898c45a7cba'">
                   <template slot="label">
                      <span>车辆类型</span>
                      <el-button icon="el-icon-edit" type="text" @click="carTypeBtn"></el-button>
                    </template>
                   <template v-for="dict in dict.type.put_task_car_type" v-if="!isUpdateCarType">
                     <span v-if="dict.value == propertyForm.carType">{{dict.label}}</span>
                   </template>
                   <template v-if="isUpdateCarType">
                     <el-select v-model="propertyForm.carType" placeholder="车辆类型"  size="small">
                       <el-option
                         v-for="dict in dict.type.put_task_car_type"
                         :key="dict.value"
                         :label="dict.label"
                         :value="dict.value"
                       />
                     </el-select>
                     <el-button class="ml10" size="mini" @click="cancelUpdate">取消</el-button>
                     <el-button type="primary" size="mini" @click="updateCarType">确认</el-button>
                   </template>
                 </el-descriptions-item>
                 <el-descriptions-item label="物品特征" :span="3" v-if="propertyForm.character">{{propertyForm.character}}</el-descriptions-item>
             </el-descriptions>
             <el-card class="box-card" style="margin-top: 5px;" v-if="propertyForm.oss != null && propertyForm.oss.length > 0">
                  <div slot="header" class="clearfix">
                    <span>图片附件</span>
                  </div>
                  <div class="text item">
                    <el-image v-for="(pic,pindex) in propertyForm.oss"
                          style="width: 100px; height: 100px;margin-right: 5px;"
                          :src="ossTransfer(pic,'one')"
                          fit="scale-down"
                          :preview-src-list="ossTransfer(propertyForm.oss,'list')"></el-image>
                  </div>
                </el-card>
            </el-tab-pane>
            <el-tab-pane label="财物日志" name="1">
              <el-timeline>
                <template v-for="(activity, index) in propertyLogOptions">
                <el-timeline-item :timestamp="activity.logTime" placement="top" type="info">
                  <el-card>
                    <!-- <el-divider content-position="left"><el-badge is-dot type="info"></el-badge></el-divider> -->
                    <el-descriptions :column="1" border :labelStyle="{width:'120px'}">
                      <!-- <el-descriptions-item label="操作时间">{{activity.createTime}}</el-descriptions-item> -->
                      <el-descriptions-item label="操作人">{{activity.operator}}</el-descriptions-item>
                      <el-descriptions-item label="操作内容">{{activity.content}}</el-descriptions-item>
                      <el-descriptions-item label="图片" v-if="activity.oss && activity.oss.length > 0">
                        <!-- <el-image
                          style="width: 120px; height: 60px;margin-right: 5px;" :src="ossTransfer(activity.oss,'one')" fit="scale-down"
                          :preview-src-list="ossTransfer(activity.oss,'list')"></el-image> -->
                          <el-image v-for="(pic,pindex) in activity.oss"
                          style="width: 120px; height: 60px;margin-right: 5px;" :src="ossTransferThumbnail(pic,'list')" fit="scale-down"
                          :preview-src-list="ossTransfer(activity.oss,'list')"></el-image>
                      </el-descriptions-item>
                    </el-descriptions>
                  </el-card>
                </el-timeline-item>
                </template>
                </el-timeline>
            </el-tab-pane>
          </el-tabs>
        </el-card>
    </el-drawer>
  </div>
</template>

<script>
  import {
    listInventory,
    getInventory,
    delInventory,
    addInventory,
    updateInventory,
    getStatisticsTask
  } from "@/api/wms/inventory";
  import {
    listProperty,
    getProperty,
    delProperty,
    addProperty,
    updateProperty,
    initPackBean,
    getPropertyByNo
  } from "@/api/oms/property";
  import {listPropertyLog} from '@/api/oms/propertyLog'
  import {inventoryDatas} from "@/api/center/index"
  import {
    listStore,
    storeTreeselect
  } from "@/api/wms/store";
  import { listStoreArea} from '@/api/wms/storeArea';
  import {
    treeselect
  } from "@/api/system/dept";
  import {listCabinetGroup } from "@/api/wms/cabinetGroup";
  import {listCabinet } from "@/api/wms/cabinet";
  import {listLocator } from "@/api/wms/locator";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  export default {
    name: "Inventory",
    dicts: ['sys_del_flag', 'wms_stock_status','wms_car_type','put_task_car_type'],
    components: {
      Treeselect
    },
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 库存表格数据
        inventoryList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 图片附件时间范围
        daterangeIntime: [],
        // 图片附件时间范围
        daterangeLastTime: [],
        // 图片附件时间范围
        daterangeNextTime: [],
        // 图片附件时间范围
        daterangeCreateTime: [],
        // 图片附件时间范围
        daterangeUpdateTime: [],
        storeOptions: [],
        storeAreaOptions:[],
        storeTree: [],
        storeName: undefined,
        deptOptions: [],
        cabinetGroupOptions:[],
        cabinetOptions:[],
        locatorOptions:[],
        statisticsOptions:[],
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          storeId: undefined,
          areaId: undefined,
          cabinetGroupId:this.$router.currentRoute.query.cabinetGroupId?this.$router.currentRoute.query.cabinetGroupId:undefined,
          cabinetId:this.$router.currentRoute.query.cabinetId?this.$router.currentRoute.query.cabinetId:undefined,
          locatorId: undefined,
          locatorIds:[],
          pno: undefined,
          rfid: undefined,
          name: undefined,
          intime: undefined,
          lastTime: undefined,
          nextTime: undefined,
          deptId: undefined,
          status: this.$router.currentRoute.query.status?this.$router.currentRoute.query.status:undefined,
          createTime: undefined,
          updateTime: undefined,
          updateBy: undefined,
          createBy: undefined,
          delFlag: undefined,
          region:undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          storeId: [{
            required: true,
            message: "仓库ID不能为空",
            trigger: "change"
          }],
          areaId: [{
            required: true,
            message: "库区ID不能为空",
            trigger: "change"
          }],
          locatorId: [{
            required: true,
            message: "库位ID不能为空",
            trigger: "change"
          }],
          pno: [{
            required: true,
            message: "物品编号不能为空",
            trigger: "blur"
          }],
          name: [{
            required: true,
            message: "物品名称不能为空",
            trigger: "blur"
          }],
          intime: [{
            required: true,
            message: "入库时间不能为空",
            trigger: "blur"
          }],
          innums: [{
            required: true,
            message: "入库数量不能为空",
            trigger: "blur"
          }],
          nums: [{
            required: true,
            message: "库存数量不能为空",
            trigger: "blur"
          }],
          deals: [{
            required: true,
            message: "处置数量不能为空",
            trigger: "blur"
          }],
          deptId: [{
            required: true,
            message: "机构id不能为空",
            trigger: "blur"
          }],
        },
        propertyForm : {
          id: undefined,
          name: undefined,
          pno: undefined,
          classifyId: undefined,
          secondClassifyId:undefined,
          thirdClassifyId:undefined,
          rfid: undefined,
          locatorId: undefined,
          status: '0',
          createTime: undefined,
          createBy: undefined,
          updateTime: undefined,
          updateBy: undefined,
          delFlag: undefined,
          storeId: undefined,
          areaId: undefined,
          character:undefined,
          oss:[]
        },
        ano:undefined,
        isUpdateCarType:false,
        drawer:false,
        activeName:0,
        propertyLogOptions:[],
        srcList:[],
        nodes1:[],
        nodes2:[],
        nodes3:[],
        nodes4:[],
        nodes5:[],
        nodes6:[],
        floorsOptions:[
          {name:'1层',value:'1'},
          {name:'2层',value:'2'},
          {name:'3层',value:'3'},
          {name:'4层',value:'4'},
          {name:'5层',value:'5'},
          {name:'6层',value:'6'},
          {name:'7层',value:'7'},
          {name:'8层',value:'8'}
        ],
        xzTabVal: 0,
        xzTabs: [
          { label: '0', name: '刑事类', badge: undefined, xzType: 'xs', delFlag: '0', delivery: undefined },
          { label: '1', name: '行政类', badge: undefined, xzType: 'xz', delFlag: '0', delivery: '0' },
        ],
      };
    },
    watch: {
      'queryParams.storeId': {
        handler(newVal, oldVal) {
          this.getStoreArea(newVal);
        },
        deep: true,
        immediate: true
      },
      'queryParams.areaId':{
        handler(newVal){
          if(newVal){
            this.storeAreaOptions.forEach(item=>{
               if(item.id == newVal){
                 let ano = item.ano;
                 this.ano = ano;
                 if(ano == 'ZX'||ano == 'DX'){
                   this.queryParams.cabinetGroupId = undefined;
                 }else{
                   this.getCabinetGroup(newVal)
                 }
               }
            })
          }
        },
        deep: true,
        immediate: true

      },
      'queryParams.cabinetGroupId': {
        handler(newVal, oldVal) {
          this.getCabinet(newVal);
          if(this.ano == 'CL'){
            this.getLocator();
          }
        },
        deep: true,
        immediate: true
      },
      'queryParams.cabinetId': {
        handler(newVal, oldVal) {
          this.getLocator(newVal);
        },
        deep: true,
        immediate: true
      },
      'queryParams.floors': {
        handler(newVal, oldVal) {
          this.getLocator(newVal);
        },
        deep: true,
        immediate: true
      },
    },
    created() {
      this.getList();
      this.getStoreTreeselect();
      this.getTreeselect();
      this.getStatistics();
    },
    methods: {
      /** 查询库存列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        this.queryParams.xzType = this.xzTabVal;
        if (null != this.daterangeIntime && '' != this.daterangeIntime) {
          this.queryParams.params["beginIntime"] = this.daterangeIntime[0];
          this.queryParams.params["endIntime"] = this.daterangeIntime[1];
        }
        if (null != this.daterangeLastTime && '' != this.daterangeLastTime) {
          this.queryParams.params["beginLastTime"] = this.daterangeLastTime[0];
          this.queryParams.params["endLastTime"] = this.daterangeLastTime[1];
        }
        if (null != this.daterangeNextTime && '' != this.daterangeNextTime) {
          this.queryParams.params["beginNextTime"] = this.daterangeNextTime[0];
          this.queryParams.params["endNextTime"] = this.daterangeNextTime[1];
        }
        if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
          this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
          this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
        }
        if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
          this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0];
          this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1];
        }
        inventoryDatas(this.queryParams).then(response => {
          this.inventoryList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      xzTabChange(e){
        this.getList()
      },
      /**地域筛选 */
      getStatistics(){
        getStatisticsTask().then(response=>{
          this.statisticsOptions = response.data.result;
        })
      },
      statisticsChange(item){
        this.queryParams.region = item.region;
        this.queryParams.pageNum = 1;
        this.getList();
      },
      carTypeBtn(){
        this.isUpdateCarType = true;
      },
      cancelUpdate(){
        this.isUpdateCarType = false;
      },
      updateCarType(){
          updateProperty(this.propertyForm).then(response=>{
            if(response.code == 200){
              this.isUpdateCarType = false;
            }
          })
      },

      /** 查询分类下拉树结构 */
      getStoreTreeselect() {
        storeTreeselect().then(response => {
          this.storeOptions = response.data;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      /** 查询库区*/
      getStoreArea(storeId){
        listStoreArea({storeId:storeId}).then(response=>{
          this.storeAreaOptions = response.rows;
        })
      },
      /** 查询智能柜信息 */
      getCabinetGroup(areaId){
        listCabinetGroup({areaId:areaId}).then(response=>{
          this.cabinetGroupOptions = response.rows;
        })
      },
      /** 查询智能柜信息 */
      getCabinet(cabinetGroupId){
        listCabinet({groupId:cabinetGroupId}).then(response=>{
          this.cabinetOptions = response.rows;
        })
      },
      getLocator(cabinetId){
        let floors = undefined;
        if(this.ano == 'PT'){
          floors = this.queryParams.floors;
        }
        if(this.queryParams.cabinetGroupId && cabinetId){
          listLocator({cabinetGroupId:this.queryParams.cabinetGroupId,cabinetId:cabinetId,floors:floors}).then(response=>{
            this.locatorOptions = response.rows;
          })
        }
      },
      deptChange() {
        this.getList();
      },
      //table统计
       getSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index < 11) {
            sums[index] = '';
            return;
          }

          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              // console.info('value===>',value)
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            // sums[index] += ' 元';
          } else {
            // sums[index] = 'N/A';
          }
        });

        return sums;
      },
      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
        this.queryParams.storeId = data.id;
        this.handleQuery();
      },
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.id,
          label: node.name,
          children: node.children
        };
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          storeId: undefined,
          areaId: undefined,
          locatorId: undefined,
          pno: undefined,
          rfid: undefined,
          name: undefined,
          intime: undefined,
          innums: undefined,
          nums: undefined,
          deals: undefined,
          lastTime: undefined,
          nextTime: undefined,
          deptId: undefined,
          remark: undefined,
          status: undefined,
          pics: undefined,
          createTime: undefined,
          updateTime: undefined,
          updateBy: undefined,
          createBy: undefined,
          delFlag: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeIntime = [];
        this.daterangeLastTime = [];
        this.daterangeNextTime = [];
        this.daterangeCreateTime = [];
        this.daterangeUpdateTime = [];
        this.queryParams.region = undefined;
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加库存";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.loading = true;
        this.reset();
        const id = row.id || this.ids
        getInventory(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.open = true;
          this.title = "修改库存";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateInventory(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addInventory(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除库存编号为"' + ids + '"的数据项？').then(() => {
          this.loading = true;
          return delInventory(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('wms/inventory/export', {
          ...this.queryParams
        }, `inventory_${new Date().getTime()}.xlsx`)
      },
      // 表单重置
      resetPropertyForm() {
        this.propertyForm = {
          id: undefined,
          name: undefined,
          pno: undefined,
          classifyId: undefined,
          secondClassifyId:undefined,
          thirdClassifyId:undefined,
          rfid: undefined,
          locatorId: undefined,
          status: '0',
          createTime: undefined,
          createBy: undefined,
          updateTime: undefined,
          updateBy: undefined,
          delFlag: undefined,
          storeId: undefined,
          areaId: undefined,
          character:undefined,
          oss:[]
        };
        this.resetForm("propertyForm");
      },
      handleInfo(row){
        this.activeName = '0'
        this.resetPropertyForm();
        const no = row.pno
        let oss = [];
          getPropertyByNo(no).then(response=>{
             this.propertyForm = response.data;
             oss = response.data.oss ? response.data.oss : [];
             let srcList = [];
             if(this.propertyForm.oss && this.propertyForm.oss.length > 0){
              this.propertyForm.oss.forEach(function(pic){
                srcList.push(pic.url);
              })
             }
             this.srcList = srcList;
             this.drawer = true;
             this.title = '财物详情'
          })
          let nodes1 = [];
          let nodes2 = [];
          let nodes3 = [];
          let nodes4 = [];
          let nodes5 = [];
          let nodes6 = [];
          listPropertyLog({'pno':row.pno}).then(response=>{
            this.propertyLogOptions = response.rows;
            // this.propertyLogOptions.forEach(item => {
            //   if(item.node == "1"){nodes1.push(item);}
            //   if(item.node == "2"){nodes2.push(item);}
            //   if(item.node == "3"){nodes3.push(item);}
            //   if(item.node == "4"){nodes4.push(item);}
            //   if(item.node == "5"){nodes5.push(item);}
            //   if(item.node == "6"){nodes6.push(item);}
            //   if(item.oss && item.oss.length > 0){
            //     oss = oss.concat(item.oss);
            //   }
            // })
            // this.nodes1 = nodes1;
            // this.nodes2 = nodes2;
            // this.nodes3 = nodes3;
            // this.nodes4 = nodes4;
            // this.nodes5 = nodes5;
            // this.nodes6 = nodes6;
            // this.propertyForm.oss = oss;
          })
      },
      handleClose(){
        this.drawer = false;
      }
    }
  };
</script>
